#include "Newton.h"

using namespace std;

double fun(double x){
    double f;
    f=1/(1+pow(x,2));
    return f;
}
int main(){
    int n=6;
    vector<double> x(n+1);
    for (double i=0;i<n+1;i++){
        x[i]=-5+10*i/n;
    }
    vector<double> y(n+1);
    for (int i=0;i<n+1;i++){
        y[i]=fun(x[i]);
    }
    Polynomial f(n);
    vector<double> a_0(n+1);
    a_0=f.makepoly(x,y);

    
    cout <<"Pn(x)=";
    for (int i=0;i<n;i++){
        cout << a_0[i];
        for(int j=0;j<i;j++){
            cout << "(x-("<< x[j]<<"))";
        }
        cout <<"+";
    }
    cout << a_0[n];
    for (int j=0;j<n;j++){
        cout << "(x-("<< x[j]<<"))";
    }
    cout <<endl;



    return 0;
}